package animation.wlh.com.animation_demo

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.widget.LinearLayout
import android.widget.Scroller

/**
 * Created by weilh on 2016/1/27.
 */
class ScrollLinearLayout : LinearLayout {
    constructor(context : Context) : super(context) {
        init(context)
    }
    constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet) {
        init(context)
    }
    constructor(context: Context, attributeSet: AttributeSet, style : Int) : super(context, attributeSet, style) {
        init(context)
    }

    var mScroller : Scroller? = null

    fun init(context : Context) {
        mScroller = Scroller(context)
    }
    override fun computeScroll() {
        super.computeScroll()
        if (mScroller == null) return
        Log.i("wlh", "computeScroll")
        if (mScroller!!.computeScrollOffset()) {
            (parent as View).scrollTo(mScroller!!.currX, mScroller!!.currY)
            invalidate()
        }
    }

}
